﻿using System.Collections.Generic;
using Missbot.Service;

namespace Missbot.AIModule.Gaming.Gift
{
    /// <summary>
    /// 礼物物品
    /// </summary>
    public class GiftItem : DbBaseEntity
    {
        /// <summary>
        /// 礼物名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 礼物描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 所需材料列表
        /// </summary>
        public Dictionary<string, int> MaterialDic { get; set; }

        /// <summary>
        /// 金币需求
        /// </summary>
        public int GoldNeed { get; set; }

        /// <summary>
        /// 羁绊值
        /// </summary>
        public int Intimate { get; set; }

        /// <summary>
        /// 魅力值
        /// </summary>
        public int Glamour { get; set; }
    }

    public static class GiftItemDA
    {
        /// <summary>
        /// 检查材料和金币是否充足
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="Mas"></param>
        /// <param name="Golds"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool Check(this GiftItem entity, Dictionary<string, int> Mas, int Golds, out string msg)
        {
            msg = string.Empty;
            var result = true;
            msg += $"金币：{Golds}/{entity.GoldNeed}\n";
            if (Golds < entity.GoldNeed)
            {
                result = false;
            }

            foreach (var (key, value) in entity.MaterialDic)
            {
                if (!Mas.ContainsKey(key))
                {
                    msg += $"{key}：0/{value}\n";
                    result = false;
                    continue;
                }

                msg += $"{key}：{Mas[key]}/{value}\n";
                if (Mas[key] < value)
                {
                    result = false;
                }
            }

            return result;
        }

        /// <summary>
        /// 获取所有礼物物品
        /// </summary>
        /// <returns></returns>
        public static List<GiftItem> GetAll()
        {
            return MongoService<GiftItem>.Get();
        }
    }
}